[UNDERTOW-2655] Fix text corruption in FileUtils.readFile when reading multi-byte characters #1834
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes text corruption in
FileUtils.readFilewhen reading multi-byte UTF-8 characters.Problem: The original implementation read the
InputStreaminto a fixed-size byte buffer (1024 bytes) and decoded each chunk independently. When a multi-byte character sequence was split across a buffer boundary, the decoder received incomplete character data, resulting in replacement characters (�) in the final string.Solution: Replaced
BufferedInputStreamwithInputStreamReaderto handle buffering and character decoding together in a streaming fashion, ensuring multi-byte character sequences are never split.Note: The implementation is copied from Java 25's
InputStreamReader#readAllAsString.This issue became more significant after fixing UNDERTOW-2337, as large form-data field values are now processed by this vulnerable function. Originally reported in Spring Framework issue #35292.
Issue: UNDERTOW-2655